package cn.edu.ujn.springboot.controller;

import cn.edu.ujn.dao.CarparkInfo;
import cn.edu.ujn.dao.ParkingSpaceInfo;
import cn.edu.ujn.dao.ParkingSpaceInfoMapper;
import cn.edu.ujn.service.IParkingSpaceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/carparkinfo")
public class ParkingSpaceInfoController {

    @Autowired
    private IParkingSpaceInfoService parkingSpaceInfoService;

    @Autowired
    private ParkingSpaceInfoMapper parkingSpaceInfoMapper;

    @GetMapping("/parkingSpace")
    public List<ParkingSpaceInfo> getList(ParkingSpaceInfo parkingSpace) {
        return parkingSpaceInfoService.selectAll(parkingSpace);
    }

    @PostMapping("/parkingSpace")
    public String addCarparkInfo(@RequestBody ParkingSpaceInfo parkingSpace) {

        return parkingSpaceInfoService.insert(parkingSpace)== 1 ? "success" : "fail";
    }

    @GetMapping("/parkingSpace/{id}")
    public ParkingSpaceInfo getParkingSpaceInfoById(@PathVariable("id") Integer id) {
        System.out.println("iiiiiiiiiiiiiiiiid"+id);
        System.out.println("fanhui"+parkingSpaceInfoMapper.selectByPrimaryKey(id));
        return parkingSpaceInfoMapper.selectByPrimaryKey(id);
    }

    @PutMapping("/parkingSpace")
    public String updateCarparkInfo(@RequestBody ParkingSpaceInfo parkingSpace) {
        return parkingSpaceInfoService.updateByPrimaryKeySelective(parkingSpace) == 1 ? "success" : "fail";
    }

    @DeleteMapping("/parkingSpace/{id}")
    public String deleteCarpark(@PathVariable Integer id){
        return parkingSpaceInfoService.deleteByPrimaryKey(id) == 1 ? "success" : "fail";
    }
}
